package com.lucas.exception;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @program: spring_cloud_lagou_homework
 * @author: lucasLu
 **/
@EqualsAndHashCode(callSuper = true)
@Data
public class MyException  extends RuntimeException {
    /**
     * 自定义错误讯息代码.
     */
    private Integer code;
    /**
     * 自定义错误讯息.
     */
    private String msg;
    /**
     * 捕获的错误消息
     */
    private Exception exception;

    public MyException(Exception exception) {
        super(exception);
    }

    public MyException(Integer code) {
        super(String.format("未知错误消息【%s】", code));
        this.code = code;
        this.msg = String.valueOf(code);
    }

    public MyException(Integer code, Exception exception) {
        super(String.format("未知错误消息【%s】", code));
        this.code = code;
        this.msg = String.valueOf(code);
        this.exception = exception;
    }

    public MyException(String msg) {
        super(msg);
        this.code = 1001;
        this.msg = msg;
    }

    public MyException(String msg, Exception exception) {
        super(msg);
        this.code = 1001;
        this.msg = msg;
        this.exception = exception;
    }

    public MyException(Integer code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    public MyException(Integer code, String msg, Exception exception) {
        super(msg);
        this.code = code;
        this.msg = msg;
        this.exception = exception;
    }
}
